
//***************************************************************************
//                           ColUtilsOpenGL
//***************************************************************************
//  Copyright (C):
//***************************************************************************

#ifndef ColUtilsOpenGL_H
#define ColUtilsOpenGL_H
#if defined(__sgi) || defined(_WIN32)
#pragma once
#endif

//---------------------------------------------------------------------------
//  Includes
//---------------------------------------------------------------------------

#include <iostream>
#include <fstream>

#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <col_import_export.h>
#include <ColGeometry.h>
#include <ColTopology.h>

namespace col
{

class COL_EXPORTIMPORT Cube
{
public:
	static const unsigned int np = 8;
	static Point3 points[8];

	static const unsigned int nqi = 6;
	static const unsigned int nti = 12;
	static unsigned int quat_indices[24];
	static unsigned int tri_indices[36];
};

class COL_EXPORTIMPORT Icosahedron
{
public:
	static REAL x;
	static REAL z;

	static const unsigned int np = 12;
	static Point3 points[12];

	static const unsigned int ni = 20;
	static unsigned int indices[60];
};

typedef COL_EXPORTIMPORT enum
{
	TRACK_STOP,
	TRACK_ROTATE,
	TRACK_ZOOM
} trackModeE;


class COL_EXPORTIMPORT Trackball
{
public:
	static Vector3 pToV( int x, int y, int width, int height );	

	Trackball();

	trackModeE getTrackMode() const;
	void getZoom( REAL &zoom ) const;
	void getRotation( REAL axis[3], REAL& ) const;

	void setViewport( int width, int height );
	void mouseMoving( int x, int y );
	void mouseClick( int button, int state, int x, int y );


private:
	static const REAL HALF_PI;
	static const REAL ROTATE_SCALE;
	static const REAL ZOOM_SCALE;

	int width, height;
	trackModeE track_mode;

	Vector3 lastPos;

	REAL angle;
	REAL zoom;
	Vector3 axis;
};

COL_EXPORTIMPORT
int printOBJ( const ColGeometry *geo, const char * file_name );

COL_EXPORTIMPORT
int loadGeometryFromFile( ColGeometry * geo, const char * file_name );

COL_EXPORTIMPORT
void drawGeometry( const ColGeometry * geo,
				   GLenum mode, // mode = GL_FILL | GL_LINE | GL_POINT
				   const GLdouble * color ); 

COL_EXPORTIMPORT
void buildGeometryFromPoints( ColGeometry * geo, 
							  const Point3 vertex[], unsigned int nvertices,
							  unsigned int face[],
							  const unsigned int face_nv[],
							  unsigned int nfaces );

COL_EXPORTIMPORT
void buildGeometryFromPoints( ColGeometry * geo,
							  const Pnt3Array &vertex,
							  vector<TopoFace> &face );

COL_EXPORTIMPORT
void makeSphere( ColGeometry * geo, unsigned int depth, REAL radius );

COL_EXPORTIMPORT
void makeCube( ColGeometry * geo, REAL radius, bool quat = false );

COL_EXPORTIMPORT
void makePlane( ColGeometry * geo, REAL xsize, REAL ysize, unsigned int vert, unsigned int hor );
	
} //namespace col

#endif //ColUtilsOpenGL_H
